<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pembayaran_bebas extends CI_Controller {

	function __construct() {
        parent::__construct();
        $this->isLogin();
		$this->num_post=10;		
		$this->load->model("master/master_set_bulanan"); 
		$this->load->model("master/master_tapel"); 	
		$this->load->model("master/master_siswa"); 
		$this->load->model("master/master_komponen"); 
		$this->load->model("pembayaran_bebas_model"); 
	}

	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}
	
	function index(){
		
		$data['main_view']='pembayaran_bebas/view';
		$this->load->view('index',$data);
	}
	
	function view_pembayaran(){
		$data['main_view']='pembayaran_bebas/view_pembayaran';
		$nis=$this->input->post('nis');
		if(empty($nis)){
			$nis=$this->uri->segment(3);
		}else{
			$nis=$this->input->post('nis');
		}
		//$komponen=$this->input->post('komponen');
		//cek nis
		$cek_nis=$this->master_siswa->cek_nis($nis);
		if($cek_nis==false){
			$this->session->set_flashdata('pesan', 'NIS tidak ditemukan');
			redirect('pembayaran_bulanan');
		}
		$data['detail_siswa']=$this->master_siswa->detail($nis);
		$tapel_aktif=$this->master_tapel->get_tapel_aktif();
		$periode=$this->master_tapel->get_periode_aktif();
		
		$list_lunas=$this->pembayaran_bebas_model->get_history($nis);
		
		
		//echo "<pre>";
		$data['list_lunas']=$list_lunas;
		//$data['det_komponen']=$this->master_komponen->edit($komponen);
		$data['tapel']=$tapel_aktif;
		$data['nis']=$nis;
		//$data['komponen']=$komponen;
		//print_r($list_tagihan);exit;
		$this->load->view('index',$data);
	}
	
	
	
	function proses_pembayaran(){
		$id_komp=$this->input->post('id_komp');
		$nominal=$this->input->post('nominal');
		$nis=$this->input->post('nis');
		$jml=count($id_komp);
		for($i=0;$i<$jml;$i++){
			if($nominal[$i]!=""){
				$insert=$this->pembayaran_bebas_model->insert_data($id_komp[$i],$nominal[$i],$nis);
			}
		}  
		redirect('pembayaran_bebas');
		$this->session->set_flashdata('pesan', 'Pembayaran Sukses Dilakukan');
		
	}
	
	function delete_pembayaran($id,$nis){
		$delete=$this->pembayaran_bebas_model->delete($id);
		$this->session->set_flashdata('pesan', 'Pembayaran berhasil dihapus');
		redirect('pembayaran_bebas/view_pembayaran/'.$nis);
	}
	

}

?>